package de.zainodis.commons.component.ui.widget;

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.AutoCompleteTextView;
import de.zainodis.commons.utils.StringUtils;

/**
 * Shows suggestion lists on focus gain
 * 
 * @author zainodis
 * 
 */
public class AutoShowAutoCompleteTextView extends AutoCompleteTextView {

   public AutoShowAutoCompleteTextView(Context context) {
	 super(context);
   }

   public AutoShowAutoCompleteTextView(Context context, AttributeSet arg1) {
	 super(context, arg1);
   }

   public AutoShowAutoCompleteTextView(Context context, AttributeSet arg1, int arg2) {
	 super(context, arg1, arg2);
   }

   @Override
   protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
	 super.onFocusChanged(focused, direction, previouslyFocusedRect);
	 boolean hasFilterables = getAdapter() != null && getAdapter().getCount() > 0;

	 if (focused && hasFilterables) {
	    // This causes to never filter and always show all results
	    performFiltering(StringUtils.EMPTY, 0);
	 }
   }

   @Override
   public boolean enoughToFilter() {
	 // This causes the dropdown box to always show
	 return true;
   }
}
